﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.HVAC.Properties;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.HVAC
{
	public partial class PipeMarkForm : System.Windows.Forms.Form
	{
		public double MinDia { get; set; }

		public PipeMarkForm(bool isView3D = false)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			this.color = this.ckbType.BackColor;
			//base.Icon = Resource.YArchitechIcon;
			this.pipeTag = new HYTagOperate();
			this.IsView3D = isView3D;
		}

		private void PipeMarkForm_Load(object sender, EventArgs e)
		{
			this.pipeTagDis = Convert.ToDouble((this.pipeTag.GetNodeValue("PipeTag", "pipeTagDis") == "") ? "500" : this.pipeTag.GetNodeValue("PipeTag", "pipeTagDis"));
			this.multiplyTagDis = Convert.ToDouble((this.pipeTag.GetNodeValue("PipeTag", "multiplyDis") == "") ? "500" : this.pipeTag.GetNodeValue("PipeTag", "multiplyDis"));
			string nodeValue = this.pipeTag.GetNodeValue("PipeTag", "markContent");
			this.pipeTag.GetNodeValue("PipeTag", "type");
			string nodeValue2 = this.pipeTag.GetNodeValue("PipeTag", "style");
			this.isTagDis = (this.pipeTag.GetNodeValue("PipeTag", "IsTagDistance") == "Yes");
			this.SetMarkStyle(nodeValue);
			if (!(nodeValue2 == "single"))
			{
				if (!(nodeValue2 == "auto"))
				{
					if (!(nodeValue2 == "multiply"))
					{
						this.rbtnSingle.Checked = true;
						this.rbtnAuto.Checked = false;
						this.rbtnMultiply.Checked = false;
						this.ckbBJMark.Enabled = false;
						this.ckbDrawSlash.Enabled = false;
						this.htbMinLength.Enabled = false;
						this.htbMinLength.ReadOnly = true;
						this.htbMinDia.Enabled = false;
						this.htbMinDia.ReadOnly = true;
						this.chkTagDiatance.Visible = false;
					}
					else
					{
						this.rbtnSingle.Checked = false;
						this.rbtnAuto.Checked = false;
						this.rbtnMultiply.Checked = true;
						this.ckbBJMark.Enabled = false;
						this.ckbDrawSlash.Enabled = true;
						this.rbtnMid.Enabled = false;
						this.htbMinLength.Enabled = false;
						this.htbMinLength.ReadOnly = true;
						this.htbMinDia.Enabled = false;
						this.htbMinDia.ReadOnly = true;
						this.chkTagDiatance.Visible = true;
						this.chkTagDiatance.Checked = this.isTagDis;
						if (!this.isTagDis)
						{
							this.htbDisToPipe.Enabled = false;
						}
					}
				}
				else
				{
					this.rbtnSingle.Checked = false;
					this.rbtnAuto.Checked = true;
					this.rbtnMultiply.Checked = false;
					this.ckbBJMark.Enabled = true;
					this.ckbDrawSlash.Enabled = false;
					this.rbtnMid.Enabled = true;
					this.htbMinLength.Enabled = true;
					this.htbMinLength.ReadOnly = false;
					this.htbMinDia.Enabled = true;
					this.htbMinDia.ReadOnly = false;
					this.chkTagDiatance.Visible = false;
				}
			}
			else
			{
				this.rbtnSingle.Checked = true;
				this.rbtnAuto.Checked = false;
				this.rbtnMultiply.Checked = false;
				this.ckbBJMark.Enabled = false;
				this.ckbDrawSlash.Enabled = false;
				this.rbtnMid.Enabled = true;
				this.htbMinLength.Enabled = false;
				this.htbMinLength.ReadOnly = true;
				this.htbMinDia.Enabled = false;
				this.htbMinDia.ReadOnly = true;
				this.chkTagDiatance.Visible = false;
			}
			if (this.pipeTag.GetNodeValue("PipeTag", "pipeMinLength") != "")
			{
				this.htbMinLength.Text = this.pipeTag.GetNodeValue("PipeTag", "pipeMinLength");
			}
			else
			{
				this.htbMinLength.Text = "1000";
			}
			this.minPipeLength = double.Parse(this.htbMinLength.Text.Trim());
			this.htbMinDia.Text = ((this.pipeTag.GetNodeValue("PipeTag", "pipeMinDia") == "") ? "20" : this.pipeTag.GetNodeValue("PipeTag", "pipeMinDia"));
			this.MinDia = double.Parse(this.htbMinDia.Text.Trim());
			this.markUpMiddleDown = this.pipeTag.GetNodeValue("PipeTag", "markUpMiddleDown");
			this.isMarkbyBJ = (this.pipeTag.GetNodeValue("PipeTag", "isMarkByBJ") == "Yes");
			this.IsDelete = (this.pipeTag.GetNodeValue("PipeTag", "IsDelete") == "Yes");
			this.htbDisToPipe.Text = this.pipeTagDis.ToString();
			if (this.IsDelete)
			{
				this.ckbDele.Checked = true;
			}
			else
			{
				this.ckbDele.Checked = false;
			}
			if (this.isMarkbyBJ)
			{
				this.ckbBJMark.Checked = true;
			}
			else
			{
				this.ckbBJMark.Checked = false;
			}
			string a = this.markUpMiddleDown;
			if (!(a == "上"))
			{
				if (!(a == "中"))
				{
					if (!(a == "下"))
					{
						this.rbtnUp.Checked = true;
						this.rbtnMid.Checked = false;
						this.rbtnDown.Checked = false;
					}
					else
					{
						this.rbtnUp.Checked = false;
						this.rbtnMid.Checked = false;
						this.rbtnDown.Checked = true;
					}
				}
				else
				{
					this.rbtnUp.Checked = false;
					this.rbtnMid.Checked = true;
					this.rbtnDown.Checked = false;
				}
			}
			else
			{
				this.rbtnUp.Checked = true;
				this.rbtnMid.Checked = false;
				this.rbtnDown.Checked = false;
			}
			if (this.pipeTag.GetNodeValue("PipeTag", "isSlash") == "Yes")
			{
				this.ckbDrawSlash.Checked = true;
			}
			if (this.IsView3D)
			{
				if (this.rbtnMultiply.Checked)
				{
					this.rbtnMultiply.Checked = false;
					this.rbtnSingle.Checked = true;
				}
				this.rbtnMultiply.Enabled = false;
				if (this.rbtnDown.Checked)
				{
					this.rbtnDown.Checked = false;
					this.rbtnUp.Checked = true;
				}
				this.rbtnDown.Enabled = false;
			}
		}

		private void PipeMarkForm_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}

		private void radioCheckedChanged(object sender, EventArgs e)
		{
			if (this.rbtnSingle.Checked)
			{
				this.ckbBJMark.Enabled = false;
				this.ckbDrawSlash.Enabled = false;
				this.ckbDele.Enabled = true;
				this.rbtnMid.Enabled = true;
				this.htbMinLength.Enabled = false;
				this.htbMinLength.ReadOnly = true;
				this.htbMinDia.Enabled = false;
				this.htbMinDia.ReadOnly = true;
				this.chkTagDiatance.Visible = false;
				this.htbDisToPipe.Enabled = true;
				this.pbMarkview.Image = YArchitech.HVAC.Properties.Resources.单选标注;
				return;
			}
			if (this.rbtnMultiply.Checked)
			{
				this.ckbBJMark.Enabled = false;
				this.ckbDrawSlash.Enabled = true;
				this.ckbDele.Enabled = true;
				this.rbtnMid.Enabled = false;
				this.htbMinLength.Enabled = false;
				this.htbMinLength.ReadOnly = true;
				this.htbMinDia.Enabled = false;
				this.htbMinDia.ReadOnly = true;
				this.chkTagDiatance.Visible = true;
				this.chkTagDiatance.Checked = this.isTagDis;
				if (!this.isTagDis)
				{
					this.htbDisToPipe.Enabled = false;
				}
				this.pbMarkview.Image = YArchitech.HVAC.Properties.Resources.多选引线标注;
				if (this.rbtnMid.Checked)
				{
					this.rbtnUp.Checked = true;
					return;
				}
			}
			else if (this.rbtnAuto.Checked)
			{
				this.ckbBJMark.Enabled = true;
				this.ckbDrawSlash.Enabled = false;
				this.rbtnMid.Enabled = true;
				this.htbMinLength.Enabled = true;
				this.htbMinLength.ReadOnly = false;
				this.htbMinDia.Enabled = true;
				this.htbMinDia.ReadOnly = false;
				this.ckbDele.Enabled = true;
				this.chkTagDiatance.Visible = false;
				this.htbDisToPipe.Enabled = true;
				this.pbMarkview.Image = YArchitech.HVAC.Properties.Resources.单选标注;
			}
		}

		private string GetMarkStyle()
		{
			string result = "";
			bool @checked = this.ckbDiameter.Checked;
			bool checked2 = this.ckbType.Checked;
			bool checked3 = this.ckbOffSet.Checked;
			bool checked4 = this.ckbOutsideDim.Checked;
			if (checked2 && !@checked && !checked3 && !checked4)
			{
				result = "style1";
			}
			else if (checked2 && @checked && !checked3 && !checked4)
			{
				result = "style2";
			}
			else if (checked2 && checked4 && !checked3 && !@checked)
			{
				result = "style21";
			}
			else if (checked2 && @checked && !checked3 && checked4)
			{
				result = "style22";
			}
			else if (checked2 && !@checked && checked3 && !checked4)
			{
				result = "style3";
			}
			else if (checked2 && @checked && checked3 && !checked4)
			{
				result = "style4";
			}
			else if (checked2 && checked4 && checked3 && !@checked)
			{
				result = "style41";
			}
			else if (checked2 && @checked && checked3 && checked4)
			{
				result = "style42";
			}
			else if (!checked2 && @checked && !checked3 && !checked4)
			{
				result = "style5";
			}
			else if (!checked2 && checked4 && !checked3 && !@checked)
			{
				result = "style51";
			}
			else if (!checked2 && @checked && !checked3 && checked4)
			{
				result = "style52";
			}
			else if (!checked2 && @checked && checked3 && !checked4)
			{
				result = "style6";
			}
			else if (!checked2 && checked4 && checked3 && !@checked)
			{
				result = "style61";
			}
			else if (!checked2 && @checked && checked3 && checked4)
			{
				result = "style62";
			}
			else if (!checked2 && !@checked && checked3 && !checked4)
			{
				result = "style7";
			}
			return result;
		}

		private void SetMarkStyle(string markStyle)
		{
			bool @checked = this.ckbDiameter.Checked;
			bool checked2 = this.ckbType.Checked;
			bool checked3 = this.ckbOffSet.Checked;
			bool checked4 = this.ckbOutsideDim.Checked;
			uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(markStyle);
			if (num <= 3944395331u)
			{
				if (num <= 2065846456u)
				{
					if (num != 1948256028u)
					{
						if (num != 1998588885u)
						{
							if (num == 2065846456u)
							{
								if (markStyle == "style51")
								{
									this.ckbDiameter.Checked = false;
									this.ckbType.Checked = false;
									this.ckbOffSet.Checked = false;
									this.ckbOutsideDim.Checked = true;
									return;
								}
							}
						}
						else if (markStyle == "style41")
						{
							this.ckbDiameter.Checked = false;
							this.ckbType.Checked = true;
							this.ckbOffSet.Checked = true;
							this.ckbOutsideDim.Checked = true;
							return;
						}
					}
					else if (markStyle == "style42")
					{
						this.ckbDiameter.Checked = true;
						this.ckbType.Checked = true;
						this.ckbOffSet.Checked = true;
						this.ckbOutsideDim.Checked = true;
						return;
					}
				}
				else if (num <= 2200214503u)
				{
					if (num != 2116179313u)
					{
						if (num == 2200214503u)
						{
							if (markStyle == "style21")
							{
								this.ckbDiameter.Checked = false;
								this.ckbType.Checked = true;
								this.ckbOffSet.Checked = false;
								this.ckbOutsideDim.Checked = true;
								return;
							}
						}
					}
					else if (markStyle == "style52")
					{
						this.ckbDiameter.Checked = true;
						this.ckbType.Checked = false;
						this.ckbOffSet.Checked = false;
						this.ckbOutsideDim.Checked = true;
						return;
					}
				}
				else if (num != 2216992122u)
				{
					if (num == 3944395331u)
					{
						if (markStyle == "style61")
						{
							this.ckbDiameter.Checked = false;
							this.ckbType.Checked = false;
							this.ckbOffSet.Checked = true;
							this.ckbOutsideDim.Checked = true;
							return;
						}
					}
				}
				else if (markStyle == "style22")
				{
					this.ckbDiameter.Checked = true;
					this.ckbType.Checked = true;
					this.ckbOffSet.Checked = false;
					this.ckbOutsideDim.Checked = true;
					return;
				}
			}
			else if (num <= 4065836486u)
			{
				if (num <= 4032281248u)
				{
					if (num != 3961172950u)
					{
						if (num == 4032281248u)
						{
							if (markStyle == "style6")
							{
								this.ckbDiameter.Checked = true;
								this.ckbType.Checked = false;
								this.ckbOffSet.Checked = true;
								this.ckbOutsideDim.Checked = false;
								return;
							}
						}
					}
					else if (markStyle == "style62")
					{
						this.ckbDiameter.Checked = true;
						this.ckbType.Checked = false;
						this.ckbOffSet.Checked = true;
						this.ckbOutsideDim.Checked = true;
						return;
					}
				}
				else if (num != 4049058867u)
				{
					if (num == 4065836486u)
					{
						if (markStyle == "style4")
						{
							this.ckbDiameter.Checked = true;
							this.ckbType.Checked = true;
							this.ckbOffSet.Checked = true;
							this.ckbOutsideDim.Checked = false;
							return;
						}
					}
				}
				else if (markStyle == "style7")
				{
					this.ckbDiameter.Checked = false;
					this.ckbType.Checked = false;
					this.ckbOffSet.Checked = true;
					this.ckbOutsideDim.Checked = false;
					return;
				}
			}
			else if (num <= 4099391724u)
			{
				if (num != 4082614105u)
				{
					if (num == 4099391724u)
					{
						if (markStyle == "style2")
						{
							this.ckbDiameter.Checked = true;
							this.ckbType.Checked = true;
							this.ckbOffSet.Checked = false;
							this.ckbOutsideDim.Checked = false;
							return;
						}
					}
				}
				else if (markStyle == "style5")
				{
					this.ckbDiameter.Checked = true;
					this.ckbType.Checked = false;
					this.ckbOffSet.Checked = false;
					this.ckbOutsideDim.Checked = false;
					return;
				}
			}
			else if (num != 4116169343u)
			{
				if (num == 4149724581u)
				{
					if (markStyle == "style1")
					{
						this.ckbDiameter.Checked = false;
						this.ckbType.Checked = true;
						this.ckbOffSet.Checked = false;
						this.ckbOutsideDim.Checked = false;
						return;
					}
				}
			}
			else if (markStyle == "style3")
			{
				this.ckbDiameter.Checked = false;
				this.ckbType.Checked = true;
				this.ckbOffSet.Checked = true;
				this.ckbOutsideDim.Checked = false;
				return;
			}
			this.ckbDiameter.Checked = false;
			this.ckbType.Checked = true;
			this.ckbOffSet.Checked = false;
			this.ckbOutsideDim.Checked = false;
		}

		private void ckbType_CheckedChanged(object sender, EventArgs e)
		{
			if (!this.ckbOffSet.Checked && !this.ckbDiameter.Checked && !this.ckbOutsideDim.Checked && !this.ckbType.Checked)
			{
				this.ckbType.Checked = true;
			}
		}

		private void ckbBJMark_CheckedChanged(object sender, EventArgs e)
		{
			if (this.ckbBJMark.Checked)
			{
				this.isMarkbyBJ = true;
				return;
			}
			this.isMarkbyBJ = false;
		}

		private void markTagInfo()
		{
			if (this.rbtnSingle.Checked)
			{
				this.markStyle = "single";
			}
			else if (this.rbtnAuto.Checked)
			{
				this.markStyle = "auto";
			}
			else if (this.rbtnMultiply.Checked)
			{
				this.markStyle = "multiply";
			}
			if (this.ckbDele.Checked)
			{
				this.IsDelete = true;
				this.pipeTag.SetNodeValue("PipeTag", "IsDelete", "Yes");
			}
			else
			{
				this.IsDelete = false;
				this.pipeTag.SetNodeValue("PipeTag", "IsDelete", "No");
			}
			if (this.rbtnUp.Checked)
			{
				this.markUpMiddleDown = "上";
			}
			else if (this.rbtnMid.Checked)
			{
				this.markUpMiddleDown = "中";
			}
			else if (this.rbtnDown.Checked)
			{
				this.markUpMiddleDown = "下";
			}
			string a = this.markStyle;
			if (!(a == "auto"))
			{
				if (a == "multiply")
				{
					if (this.ckbDrawSlash.Checked)
					{
						this.isHaveSlash = true;
					}
					else
					{
						this.isHaveSlash = false;
					}
				}
			}
			else
			{
				this.isMarkbyBJ = this.ckbBJMark.Checked;
			}
			this.markContent = this.GetMarkStyle();
			this.pipeTag.SetNodeValue("PipeTag", "markContent", this.markContent);
			this.minPipeLength = double.Parse(this.htbMinLength.Text.Trim());
			this.pipeTag.SetNodeValue("PipeTag", "pipeMinLength", this.htbMinLength.Text);
			this.MinDia = double.Parse(this.htbMinDia.Text.Trim());
			this.pipeTag.SetNodeValue("PipeTag", "pipeMinDia", this.htbMinDia.Text);
			if (this.rbtnSingle.Checked)
			{
				this.pipeTag.SetNodeValue("PipeTag", "style", "single");
			}
			else if (this.rbtnAuto.Checked)
			{
				this.pipeTag.SetNodeValue("PipeTag", "style", "auto");
			}
			else if (this.rbtnMultiply.Checked)
			{
				this.pipeTag.SetNodeValue("PipeTag", "style", "multiply");
			}
			if (this.ckbDrawSlash.Checked)
			{
				this.pipeTag.SetNodeValue("PipeTag", "isSlash", "Yes");
			}
			else
			{
				this.pipeTag.SetNodeValue("PipeTag", "isSlash", "No");
			}
			if (this.isMarkbyBJ)
			{
				this.pipeTag.SetNodeValue("PipeTag", "isMarkByBJ", "Yes");
			}
			else
			{
				this.pipeTag.SetNodeValue("PipeTag", "isMarkByBJ", "No");
			}
			if (this.rbtnUp.Checked)
			{
				this.pipeTag.SetNodeValue("PipeTag", "markUpMiddleDown", "上");
			}
			else if (this.rbtnMid.Checked)
			{
				this.pipeTag.SetNodeValue("PipeTag", "markUpMiddleDown", "中");
			}
			else if (this.rbtnDown.Checked)
			{
				this.pipeTag.SetNodeValue("PipeTag", "markUpMiddleDown", "下");
			}
			if (this.pipeTagDis < 0.0)
			{
				this.pipeTagDis = 500.0;
				this.htbDisToPipe.Text = "500";
			}
			this.pipeTagDis = Convert.ToDouble(this.htbDisToPipe.Text);
			this.pipeTag.SetNodeValue("PipeTag", "pipeTagDis", this.pipeTagDis.ToString());
			if (this.isTagDis)
			{
				this.pipeTag.SetNodeValue("PipeTag", "IsTagDistance", "Yes");
			}
			else
			{
				this.pipeTag.SetNodeValue("PipeTag", "IsTagDistance", "No");
			}
			this.pipeTag.SaveXml();
		}

		private void btnMark_Click(object sender, EventArgs e)
		{
			this.markTagInfo();
			base.DialogResult = DialogResult.Yes;
		}

		private void rbtnMid_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbtnMid.Checked)
			{
				this.htbDisToPipe.Enabled = false;
				return;
			}
			this.htbDisToPipe.Enabled = true;
		}

		private void chkTagDiatance_CheckedChanged(object sender, EventArgs e)
		{
			if (this.chkTagDiatance.Checked)
			{
				this.isTagDis = true;
				this.htbDisToPipe.Enabled = true;
				return;
			}
			this.isTagDis = false;
			this.htbDisToPipe.Enabled = false;
		}

		private void htbDisToPipe_TextChanged(object sender, EventArgs e)
		{
		}

		private void htbDisToPipe_Validated(object sender, EventArgs e)
		{
			if (double.Parse(this.htbDisToPipe.Text.Trim()) > 99999.0)
			{
				YJKMessageBox.Information("输入数值过大，请重设！");
				this.htbDisToPipe.Undo();
				this.htbDisToPipe.Focus();
			}
		}

		public bool IsDelete;

		public string markUpMiddleDown = "";

		public string markContent = "";

		public string markStyle = "";

		public double minPipeLength;

		public bool isMarkbyBJ;

		public bool isTagDis = true;

		public bool isHaveSlash;

		private System.Drawing.Color color;

		public double pipeTagDis;

		public double multiplyTagDis;

		private HYTagOperate pipeTag;

		private bool IsView3D;
	}
}
